<template>
	<div>
		<Row>
			<Col class="p-1" :xs="24" :sm="24" :md="12" :lg="8" :xl="6" :xxl="4">
			<Input class="w-100" v-model="searchKey" placeholder="请输入课程名称" />
			</Col>
		</Row>
		<Row>
			<div class="w-100 d-flex justify-content-end align-items-center ">
				<Button class="m-1" type="primary" shape="circle" @click="searchs" icon="ios-search">查询</Button>
			</div>
		</Row>
		<div class="mt-1">
			<Row>
				<Col class="p-1" v-for="(row, index) in tableInfo.data" :xs="24" :sm="24" :md="12" :lg="8" :xl="6"
					:xxl="6">
				<div :style="'background-image:url('+row.cover+'); background-size: 100% 100%;'" 
					class="text-xss rounded shadow overflow-hidden">
					<div class="p-2 bg-black-80 text-fuguang d-flex text-lg justify-content-start text-blod">
						<span>{{row.kcname}}</span>
					</div>
					<div class="p-2 bg-black-50 text-fuguang d-flex justify-content-end">
						<span>{{row.kcid}}</span>
					</div>
					<div class="p-2 bg-black-50 text-fuguang d-flex justify-content-around">
						<span>{{ formatDate(row.st) }}</span>
						<span>{{ formatDate(row.et) }}</span>
					</div>
					
					
					<div class="p-2 bg-black-50 position-relative  d-flex justify-content-between align-items-center">
						<div class="w-25  position-relative">
							<div class="padding-top-100"></div>
							<div class="position-absolute rounded-circle overflow-hidden top0">
								<img class="w-100 h-100" :src="row.jcover"/>
							</div>
							<div class="text-danhong text-center">{{row.jlname}}</div>
						</div>
						<div class="w-75 text-danhong ">
							<div class="p-2 d-flex justify-content-between align-items-center">
								<span class="text-fuguang pl-1">
									<span class="iconfont icon-yishangkekeshishu"></span>
									<span class="ml-1">{{row.cs}}</span>
								</span>
								<span class="text-danhong text-lg text-blod">￥{{row.price / 100}}</span>
							</div>
							
							<div class="p-2 d-flex justify-content-between align-items-center">
								<div class="text-fuguang">
									<span class="iconfont icon-paidui pl-1">{{row.ybrs}}</span>
									<span class="iconfont icon-min pl-1">{{row.zxrs}}</span>
									<span class="iconfont icon-icon-com-max-user pl-1">{{row.zdrs}}</span>
								</div>
								<span class="text-danhong text-blod">
									<span v-if="row.zt == 'C'">已取消</span>
									<span v-if="row.zt == 'D'">进行中</span>
									<span v-if="row.zt == 'F'">已完成</span>
									<span v-if="row.zt == 'B'">报名中</span>
								</span>
							</div>
						</div>
					</div>
					
					

					<div class="p-1 bg-black-50 d-flex justify-content-end">
						<Button class="text-xss ml-2" type="primary" size="small" @click="show(row.kcid)">详细</Button>

					</div>
				</div>
				</Col>
			</Row>
		</div>
		<div>
			<Page class="text-right mt-3" :page-size="tableInfo.pageSize" @on-change="pageSearch"
				:total="tableInfo.total" />
		</div>
	</div>
</template>
<script>
	export default {
		data: function() {
			return {
				searchKey: "",
				tableInfo: {
					currentPage: 1,
					pageSize: 12,
					total: 0,
					data: []
				}
			}
		},
		methods: {
			init: function() {
				this.tableInfo.currentPage = 0;
				this.search();
			},
			newUser: function() {
				this.$router.push({
					path: "/kc/new"
				})
			},
			show: function(kcid) {
				this.$router.push({
					path: "/kc/detail?id=" + kcid
				})
			},
			remove: function(kcid) {
				this.message.confirm({
					title: "删除提示",
					content: "即将删除场馆，确定吗？",
					onOk: () => {
						this.http.delete({
							url: "/kc/info",
							param: {
								kcid
							}
						}).then(data => {
							this.search();
						});
					},
					onCancel: () => {
						this.message.info('操作已取消');
					}
				});
			},
			searchs: function() {
				this.tableInfo.currentPage = 1;
				this.search();
			},
			search: function() {
				this.http.get({
					url: "/kc/page",
					param: {
						// 传一个当前页
						current: this.tableInfo.currentPage,
						size: this.tableInfo.pageSize,

					}
				}).then(data => {
					this.tableInfo.data = data.records;
					this.tableInfo.currentPage = data.current;
					this.tableInfo.total = data.total;
					this.tableInfo.pageSize = data.size;
				});
			},
			pageSearch: function(changedPage) {
				this.tableInfo.currentPage = changedPage;
				this.search();
			},
			formatDate(dateString) {
			      if (!dateString) return '无日期'
			      const date = new Date(dateString)
			      
			      // 处理IOS日期格式时差问题（如果后端返回的是UTC时间）
			      const offset = date.getTimezoneOffset() * 60000
			      const localDate = new Date(date.getTime() - offset)
			      
			      return localDate.toISOString().split('T')[0]
			    }
		},
		created: function() {
			this.init();
		}
		
	}
</script>

<style>

</style>